package com.zhl.charset3;

import java.io.UnsupportedEncodingException;
import java.util.Arrays;

public class Test1 {
    public static void main(String[] args) throws Exception {
        //1.编码
        String str = "a我b";
        byte[] bytes = str.getBytes(); //现在默认的是UTF-8编码
        System.out.println(Arrays.toString(bytes));
        //按照指定的字符集进行编码
        byte[] bytes2 = str.getBytes("GBK");
        System.out.println(Arrays.toString(bytes2));


        //2.按照指定的字符集解码
        String str1 = new String(bytes);        //按照默认的UTF-8解码
        System.out.println(str1);
        String str2 = new String(bytes, "GBK");
        System.out.println(str2);

    }
}
